package com.itheima;

import java.util.ArrayList;

public class UserDao {
    static ArrayList<User> list=new ArrayList<>();
    static {
        User u1=new User("-1","1","1","1","1","5","4");
        list.add(u1);
    }

    public void setList(User u) {
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getId().equals(u.getId())){
                list.set(i,u);
            }
        }
    }


    public ArrayList<User> getList() {
        return list;
    }

    public void addUser(User u){
        list.add(u);

    }
    public User findOne(String id){
        int index = 0;
        for (int i = 0; i < list.size(); i++) {
            if(id.equals(list.get(i).getId())){
                index=i;
            }
        }
        return list.get(index);
    }

    public void delete(String id) {
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getId().equals(id)){
                list.remove(i);
            }
        }
    }
}
